<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择标签界面</title>
<link rel="stylesheet" href="${base!}/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
<script type="text/javascript" src="${base!}/resources/js/jquery.js"></script>
<script type="text/javascript" src="${base!}/js/jquery.ztree.all-3.4.min.js"></script>
<script type="text/javascript" src="${base!}/js/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
var base='${base!}';
var storeId='${storeId!}';
var api = frameElement.api, W = api.opener, D = W.document; 
/*
 * 标签配置
 */
var setting6 = {
		data: {
			simpleData: {
				enable: true
			}
		},
		edit: {
			enable: false,
			showRemoveBtn: false,
			showRenameBtn: false
		},
		callback: {
			onClick: onClick6
		},
		view: {
			dblClickExpand: false,
			fontCss: getFont,
			nameIsHTML: true
		},
		check: {
			enable: true,
			chkStyle: "checkbox",
			chkboxType: { "Y": "s", "N": "s" }
		}
};
var zTree6;
$(document).ready(function(){
	zTree6 = $.fn.zTree.init($("#tree_location"), setting6);
	initTree6();
});
function onClick6(e, treeId, treeNode) {

};
function getFont(treeId, node) {
	return node.font ? node.font : {};
};
function initTree6(){
	$.ajax({
		type: 'POST',
		dataType : "json",
		url: base+"/store/admin/getTagsTree.html?storeId="+storeId,
		error: function () {//请求失败处理函数
			$.dialog.alert("请求失败!");
		},
		success:function(data){ //请求成功后处理函数。
			refreshTree6(data);	
		}
	});
};
function refreshTree6(data){
	zTree6.addNodes(null, data);
	var zTree = $.fn.zTree.getZTreeObj("tree_location");
	var nodes = zTree.transformToArray(zTree.getNodes());
	for ( var i = 0; i < nodes.length; i++) {
		if(nodes[i].attributes.type!=null && nodes[i].attributes.type==1){
			nodes[i].checked = true;
			zTree.updateNode(nodes[i]);
		}
	}
};
/*
 * 保存动作
 */
function save() {
	var treeObj = $.fn.zTree.getZTreeObj("tree_location");
	var nodes = treeObj.getCheckedNodes(true);
	var ids = new Array();
	var names = new Array(); 
	var flg=1;
	for(var i=0;i<nodes.length;i++){
		if(nodes[i].id!=-22){
			if(nodes[i].name.indexOf('&nbsp;&nbsp;[<span')>0){
				nodes[i].name=nodes[i].name.substring(0,nodes[i].name.indexOf('&nbsp;&nbsp;[<span'))
			}
			ids[i]=nodes[i].id;
			names[i]=nodes[i].name;
		}else{
			flg=0;
		}
	}
	if(flg==0){
		D.getElementById("tagIds").value=ids.toString().substring(1,names.toString().length);
		D.getElementById("tagName").value=names.toString().substring(1,names.toString().length);
	}else{
		D.getElementById("tagIds").value=ids;
		D.getElementById("tagName").value=names;
	}
	api.close();
};
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};
</script>
</head>
<body>
<!--显示标签树-->
<div id="menuLocation" class="c_l_bg"  style="width:100%;background-color:#fff;z-index:10;">
	<ul id="tree_location" class="ztree" style="margin-top:0; width:250px;"></ul>
</div>
</body>
</html>